const service = require('../service')
const msg = require('../util/ctx_body')
const upload = require('../util/upload')

exports.upload = async (ctx, next) => {
  let body = ctx.request.body;
  let files = ctx.request.body.files;
  try {
    await service.work.upload(files, body.fields.name)
    msg.resultUtil(ctx, 200);
  }
  catch(err) {
    msg.resultUtil(ctx, 400, err, '上传失败')
  }
}

exports.files = async (ctx, next) => {
  let query = ctx.query
  let files = await service.work.findFiles(query.start, query.limit)
  msg.resultUtil(ctx, 200, files)
}